<?

if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'meta',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
register_sidebar(array(
'name' => 'bottom',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
}


/* 
Function Name: Time Since 
Function URI: http://binarybonsai.com/wordpress/timesince
Description: Tells the time between the entry being posted and the comment being made.
Author: Michael Heilemann & Dunstan Orchard
Author URI: http://binarybonsai.com
*/
function time_since($older_date, $newer_date = false)
{
	// array of time period chunks
	$chunks = array(
	array(60 * 60 * 24 * 365 , 'year'),
	array(60 * 60 * 24 * 30 , 'month'),
	array(60 * 60 * 24 * 7, 'week'),
	array(60 * 60 * 24 , 'day'),
	array(60 * 60 , 'hour'),
	array(60 , 'minute'),
	);
	
	// $newer_date will equal false if we want to know the time elapsed between a date and the current time
	// $newer_date will have a value if we want to work out time elapsed between two known dates
	$newer_date = ($newer_date == false) ? (time()+(60*60*get_settings("gmt_offset"))) : $newer_date;
	
	// difference in seconds
	$since = $newer_date - $older_date;
	
	// we only want to output two chunks of time here, eg:
	// x years, xx months
	// x days, xx hours
	// so there's only two bits of calculation below:

	// step one: the first chunk
	for ($i = 0, $j = count($chunks); $i < $j; $i++)
		{
		$seconds = $chunks[$i][0];
		$name = $chunks[$i][1];

		// finding the biggest chunk (if the chunk fits, break)
		if (($count = floor($since / $seconds)) != 0)
			{
			break;
			}
		}

	// set output var
	$output = ($count == 1) ? '1 '.$name : "$count {$name}s";

	// step two: the second chunk
	if ($i + 1 < $j)
		{
		$seconds2 = $chunks[$i + 1][0];
		$name2 = $chunks[$i + 1][1];
		
		if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0)
			{
			// add to output var
			$output .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
			}
		}
	
	return $output;
}

// Get the date of the last comment for a particular post.
function last_comment_date($post_id) {
	global $wpdb;
	
	$date = $wpdb->get_results("
		SELECT comment_date_gmt FROM `$wpdb->comments`
		WHERE comment_post_id = $post_id
		ORDER BY comment_date_gmt DESC
		LIMIT 1", ARRAY_N);

	return $date[0][0];
}

function need_excerpt() { // Fakes an excerpt if needed
        global $post;

	$text = get_the_content('');
	$text = apply_filters('the_content', $text);
	$text = str_replace(']]>', ']]&gt;', $text);
	$text = strip_tags($text);
	$excerpt_length = 55;
	$words = explode(' ', $text, $excerpt_length + 1);
	if (count($words) > $excerpt_length) {
		return true;
	}
        return false;
}


function time_since_start() {
	global $wpdb;
	if ( !$time_since_start = wp_cache_get( 'time_since_start', 'function' ) ) {
		$tss = $wpdb->get_results( "SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1" );
		
		$time_since_start = $tss[0]->post_date;
		wp_cache_add( 'time_since_start', $time_since_start, 'function' );
	}

	if ( function_exists('time_since') ) { return time_since( abs( strtotime( $time_since_start ) . " GMT" ), time() ); }
	return $time_since_start;
}


// Altered from original by Dougal, to enable seperation of categories.
// Fixes contributed by Douglas.
// Mashed up for Wordpress 2.1

function get_grouped_links_list($order = 'name', $hide_if_empty = 'obsolete') {
	echo "<h2>FIXME  get_grouped_links_list</h2>";
}

// Checks to see if there any pages.
function check_num_pages() {

	// Query pages.
	$pages = & get_pages($args);
	if ( !$pages ) {
		return false;
	}
	
	return true;
}




/*
Plugin Name: Category Cloud + Monthly Cloud by Andy Peatling
Plugin URI: http://zak.greant.com/
Description: Template tag to display a categories in a tag cloud
Version: 0.1.1
Author: Zak Greant
Modified for Durable by: Andy Peatling
Author URI: http://zak.greant.com
*/

/*
New BSD License (http://www.opensource.org/licenses/bsd-license.php)
Category Cloud, Copyright (c) 2006, Foo Associates Inc.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
 * Neither the name of Foo Associates Inc. nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
Thanks to Matt Kingston (http://www.hitormiss.org/).
Matt wrote a plugin called Weighted Categories that I stole ideas from.
*/

function mk_step($min, $max, $counts){
  return ($max - $min) / (max($counts) - min($counts) + 1);
}

function mk_stepped_base($base, $step, $count){
  return $base + $step * $count;
}

function monthly_cloud(
	$font_min          = 9, /* Minimum font size */
	$font_max          = 18, /* Maximum font size */
	$font_unit         = 'px' /* Font unit */
) {
	echo "<h2>FIXME monthly_cloud</h2>";

}

/*
Plugin Name: Category Cloud Widget (Modified for bundled use)
Plugin URI: http://leekelleher.com/wordpress/plugins/category-cloud-widget/
Description: Adds a sidebar widget to display the categories as a tag cloud.
Author: Lee Kelleher
Version: 1.1.1
Author URI: http://leekelleher.com/
*/
function category_cloud($limit = 9999999) {
	echo "<h2>FIXME category_cloud</h2>";
}

?>
